package com.ydw.datahub.dao.impl;

import com.ydw.datahub.dao.MysqlDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2018/9/10.
 */
@Repository
public class MysqlDaoImpl implements MysqlDao {

    @Autowired
    JdbcTemplate jdbcTemplate;


    @Override
    public void query(DataSourceProperties dataSourceProperties, String sql, HashMap<String,String> result) {
        jdbcTemplate.setDataSource(dataSourceProperties.initializeDataSourceBuilder().build());
        Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
        stringObjectMap.entrySet().forEach(x->{
            result.put(x.getKey(),x.getValue().toString());
        });
    }
}
